
import { $Toptips } from '../../../../components/CompRouter';

const app = getApp();
const Froms = {
    NPOS: "npos",
    POS: "pos"
};

var from = "";
var profitType = "";
var date = "";
Page({

    data: {
        agentData: {agentName: "全部"},
    },

    onLoad: function (options) {
        from = options.from;
        profitType = options.profitType;
        date = options.date;
    },

    selectAgent:function(){
        wx.navigateTo({
            url: '../../agentManage/agentQurey/agentQurey?pageType=agentSelection'
        });
    },

    onSearch: function (e) {
        let errorMessage = this._checkForm(e.detail.value);
        if (errorMessage) {
            $Toptips.error({text: errorMessage});
        } else {
            this._onFilter(e.detail.value);
        }
    },

    /**
     * 开始过滤
     * @private
     */
    _onFilter(values)  {
        let agentId = this.data.agentData["agentId"] ? this.data.agentData["agentId"]: app.globalData.userData.agentId;
        let params = "?profitType=" + profitType
            + "&date=" + date
            + "&storeId=" + values.storeId
            + "&agentId=" + agentId;

        let url = "";
        if (from && from === Froms.NPOS) {
            url = "../nposResult/nposDetails/nposDetails" + params;
        } else {
            url = "../posResult/posDetails/posDetails" + params;
        }

        wx.navigateTo({
          url: url
        });
    },

    _checkForm(values) {
        return "";
    }

});